﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;

namespace DAO
{
    public class NhaXuatBanDAO
    {
        public List<NhaXuatBanDTO> LayDanhSachNXB()
        {
            List<NhaXuatBanDTO> list = new List<NhaXuatBanDTO>();
            try
            {
                QLTVEntities contex = new QLTVEntities();
                var query = from nxb in contex.NHA_XUAT_BANList
                            select nxb;
                foreach (var nxbEF in query)
                {
                    NhaXuatBanDTO nxbDTO = new NhaXuatBanDTO();
                    nxbDTO.MaNhaXuatBan = nxbEF.MaNhaXuatBan;
                    nxbDTO.TenNhaXuatBan = nxbEF.TenNhaXuatBan;
                    list.Add(nxbDTO);
                }
            }
            catch (System.Exception)
            {
            }
            return list;
        }

        public void ThemNhaXuatBan(NhaXuatBanDTO nxbDTO)
        {
            try
            {
                QLTVEntities contex = new QLTVEntities();
                NHA_XUAT_BAN nxbEF = new NHA_XUAT_BAN();
                nxbEF.TenNhaXuatBan = nxbDTO.TenNhaXuatBan;
                contex.AddToNHA_XUAT_BANList(nxbEF);
                contex.SaveChanges();
            }
            catch (System.Exception)
            {
            }
        }
    }
}
